#ifndef PAGEMAPPINGHEAP_H
#define PAGEMAPPINGHEAP_H

#include "IMemory.h"

class CPageMappingHeap : public IPageMappingHeap
{
public:
	static UINT_PTR PlatformReserveSpace(size_t sz);

public:
	CPageMappingHeap(UINT_PTR addressSpaceStart, UINT_PTR addressSpaceEnd, const char* sName);
	CPageMappingHeap(size_t addressSpace, const char* sName);
	~CPageMappingHeap();

public: // IPageMappingHeap Members
	virtual void Release();

	virtual size_t GetGranularity() const;
	virtual bool IsInAddressRange(void* ptr) const;

	virtual void* Map(size_t sz);
	virtual void Unmap(void* ptr, size_t sz);

private:
	static size_t PlatformGetPageSize();
	static void PlatformReleaseSpace(UINT_PTR start, UINT_PTR end);
	static void* PlatformMapPage(void* base, size_t pageSize);
	static void PlatformUnMapPage(void* base, size_t pageSize);

private:
	CPageMappingHeap(const CPageMappingHeap&);
	CPageMappingHeap& operator = (const CPageMappingHeap&);

private:
	void Init(UINT_PTR start, UINT_PTR end, const char* sName);

private:
	CryCriticalSectionNonRecursive m_lock;

	size_t m_pageSize;
	UINT_PTR m_addressSpaceStart;
	UINT_PTR m_addressSpaceEnd;
	std::vector<uint32> m_pageBitmap;
};

#endif
